/**
 * 
 */
package com.pxingg.encrypt.crc;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author pxingg
 * 
 */
public class CRCTest
{
    /**
     * @throws java.lang.Exception
     */
    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @AfterClass
    public static void tearDownAfterClass() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception
    {
    }

    /**
     * Test method for {@link com.pxingg.encrypt.crc.CRC#sumCRC8(byte[], int)}.
     */
    @Test
    public final void testSumCRC8()
    {
        final byte data[] = {
            (byte) 0XAA, (byte) 0XBB, (byte) 0X02, (byte) 0XFF, (byte) 0X0F, (byte) 0X00, (byte) 0X00, (byte) 0X75
        };

        Assert.assertEquals(CRC.sumCRC8(data, data.length - 1), data[data.length - 1]);

        final byte data2[] = {
            (byte) 0XAA, (byte) 0XBB, (byte) 0X02, (byte) 0X00, (byte) 0X00, (byte) 0X00, (byte) 0X00, (byte) 0X67
        };

        Assert.assertEquals(CRC.sumCRC8(data2, data2.length - 1), data2[data2.length - 1]);

        final byte data3[] = {
            (byte) 0XAA, (byte) 0XBB, (byte) 0X02, (byte) 0XFE, (byte) 0X0F, (byte) 0X00, (byte) 0X00, (byte) 0X74
        };
        Assert.assertEquals(CRC.sumCRC8(data3, data3.length - 1), data3[data3.length - 1]);

    }
}
